<template>
  <div class="t-datetimeRange-picker">
    <el-input
      type="textarea"
      :autosize="{ minRows: 1 }"
      resize="none"
      :value="moduleValue ? moduleValue.join('至') : ''"
      :disabled="disabled"
      readonly
    ></el-input>
    <el-date-picker
      v-model="moduleValue"
      ref="datetimerangepacker"
      type="datetimerange"
      format="yyyy-MM-dd HH:mm:ss"
      value-format="yyyy-MM-dd HH:mm:ss"
      prefix-icon="none"
      :editable="false"
      :disabled="disabled"
      @change="handleChange"
    >
    </el-date-picker>
  </div>
</template>
<script>
export default {
  name: "TDateTimeRangePicker",
  props: {
    value: {
      type: String,
      default: "",
      require: true,
    },
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {};
  },
  computed: {
    moduleValue: {
      get() {
        return this.value ? this.value.split("至") : [];
      },
      set(val) {
        this.$emit("input", val?.length ? val.join("至") : "");
      },
    },
  },
  methods: {
    handleFocus() {
      const datetimerangepacker = this.$refs.datetimerangepacker;
      if (datetimerangepacker) {
        this.$nextTick(() => {
          datetimerangepacker.focus();
        });
      }
    },
    focus() {
      this.handleFocus();
    },
    handleChange(value) {
      this.$emit("change", value);
    },
  },
};
</script>
<style lang="scss" scoped>
.t-datetimeRange-picker {
  position: relative;
}
.el-date-editor {
  width: 100%;
  left: 0;
  position: absolute;
  top: 0;
  z-index: -1;
}
</style>
